<template>
  <div>
    <!-- table -->
    <BreakSpace label="旧件交接信息" :containerStyle="{ marginBottom: '10px' }" />
    <FormPanel ref="formPanel" :list="formList" :cols="4" :formType="'add'" labelWidth="110" :isSubmitBtn="false" @formChange="formChangeHandle" />
    <BreakSpace label="上传视频/压缩文件" :containerStyle="{ marginBottom: '10px' }" />
    <Spin :spinning="loading" tip="Loading...">
      <FilterTable
        ref="fileTable"
        :columns="columnsFile"
        columnsRef="whbydUploadFile"
        :isSelectColumn="false"
        :onColumnsChange="columnsFile => (this.columnsFile = columnsFile)"
        height=auto
        :dataSource="list"
      />
    </Spin>
    <div style="padding-top: 3rem"></div>
    <BreakSpace label="操作记录" :containerStyle="{ marginBottom: '10px' }" />
    <FilterTable
      ref="table1"
      :columns="columns1"
      :datakey="'records'"
      :isSelectColumn="false"
      :onColumnsChange="(columns) => (this.columns1 = columns)"
      height="auto"
      :isPagination=false
    > </FilterTable>
    <div style="padding-top: 3rem"></div>
    <!-- <FormPanel ref="formPanel1" :list="formList1" :cols="1" :formType="'add'" labelWidth="110" :isSubmitBtn="false" @formChange="formChangeHandleFile" /> -->
    <!-- <div style="padding-top: 3rem"></div> -->
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right',
      }"
    >
      <!-- <multiuse-button type="primary" @click="apply">通过</multiuse-button>
      <multiuse-button type="primary" @click="saveDialog">驳回</multiuse-button> -->
      <multiuse-button @click="closeDialog">关 闭</multiuse-button>
    </div>
  </div>
</template>
<script>
import { applyDestory } from '@/api/usedPartsDestructionFactory/UsedPartsHandoverQuery';
import { getPartType } from '@/api/dictionary';

export default {
  props: ['editRow'],
  // mixins: [dictionary],
  data() {
    return {
      dataList: [],
      dataList1: [],
      visible: false,
      visibleDrawer: false,
      collapse: false,
      columns1: this.creatHeader1(),
      infoId: null,
      flterValue: {}, //参数
      // fetchParams: {}, //ipa 接口
      selectedRows: [], //选中经销商
      formList: this.createFormList(),
      saveData: null,
      activeName: '审核记录',
      saveDataFile: {},
      visibleList: false,
      columnsFile: this.createdTable(),
      list: [],
    };
  },
  created() {
    this.assignment();
  },
  mounted() {
    this.$refs.fileTable.$refs.pageTable.EXECUTE_INSERT(this.editRow.fileList);
  },
  methods: {
    async assignment() {
      let res = await getPartType({ type: 5531 });
      for (let row in this.editRow) {
        this.formList.map((x) => {
          // if (row == 'fileList' && x.fieldName == 'wayFiles') {
          //   x.initialValue = this.editRow.fileList.map((f) => ({ name: f.title, url: f.fileUrl }));
          // }
          if (x.fieldName == 'destoryStatus') {
            x.initialValue = res.data.find((x) => x.codeId == this.editRow.destoryStatus).codeCnDesc;
          }
          if (x.fieldName == row) {
            x.initialValue = this.editRow[row];
          }
        });
      }
      let res1 = await getPartType({type: 5533});
      this.formList.find((x) => x.fieldName == 'ifQualify').itemList = res1.data.map((x) => ({ value: x.codeId, text: x.codeCnDesc }));
      this.$refs.table1.$refs.pageTable.EXECUTE_INSERT(this.editRow.logDTOList);
    },
    onCellChange(columns, row) {
      let sum = 0;
      this.$refs.table.$refs.pageTable.list.map((x) => {
        console.log(x);
        sum += Number(x.pestructionCount);
      });
      this.formList.find((x) => x.fieldName == 'destoryCount').initialValue = sum;
      this.formList.find((x) => x.fieldName == 'cmsClaimCount').initialValue = this.$refs.table.$refs.pageTable.list.length;
    },
    add() {
      this.visibleList = true;
    },
    closeAdd() {
      this.visibleList = false;
    },
    saveAdd(val) {
      this.visibleList = false;
      let list = Object.assign([], val);
      let pageList = this.$refs.table.$refs.pageTable.list;
      val.map((x) => {
        if (pageList.find((f) => f.claimId != x.claimId)) {
          list.push(x);
        }
      });
      this.$refs.table.$refs.pageTable.EXECUTE_DELETE(this.$refs.table.$refs.pageTable.list);
      this.$refs.table.$refs.pageTable.EXECUTE_INSERT(list);
      this.formList.find((x) => x.fieldName == 'cmsClaimCount').initialValue = this.$refs.table.$refs.pageTable.list.length;
      let num = 0;
      this.$refs.table.$refs.pageTable.list.map((x) => {
        num += Number(x.pestructionCount || 0);
      });
      this.formList.find((x) => x.fieldName == 'destoryCount').initialValue = num;
    },
    formChangeHandle(val) {
      this.saveData = val;
    },
    formChangeHandleFile(val) {
      this.saveDataFile = val;
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = val;
    },
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(this.selectedRows);
    },
    deleteHandle(row) {
      this.$refs.table.$refs.pageTable.EXECUTE_DELETE([row]);
    },
    //保存
    // async saveDialog() {
    //  this.$refs.formPanel.SUBMIT_FORM();
    //   let fileList = [];
    //   if (this.saveData) {
    //     let save = Object.assign({}, this.saveData);
    //     this.saveData.wayFiles.map((x) => {
    //       fileList.push({ title: x.name, fileUrl: x.url });
    //     });
    //     save.fileList = fileList;
    //     save.destoryStatus = 55311012;

    //     for (let a in this.editRow) {
    //       if (save[a]) {
    //         this.editRow[a] = save[a];
    //       }
    //     }
    //     console.log(this.editRow);
    //     let res = await updateByPtId(this.editRow);
    //     if (res.resultCode == 200) {
    //       this.$emit('save');
    //     }
    //   } else {
    //     this.$notify({
    //       title: '警告',
    //       message: '请输入正确的数据!',
    //       type: 'warning',
    //     });
    //   }
    // },
    // async apply() {
    //   this.$refs.formPanel.SUBMIT_FORM();
    //   let fileList = [];
    //   if (this.saveData) {
    //     let save = Object.assign({}, this.saveData);
    //     this.saveData.wayFiles.map((x) => {
    //       fileList.push({ title: x.name, fileUrl: x.url });
    //     });
    //     save.fileList = fileList;
    //     save.destoryStatus = 55311013;

    //     for (let a in this.editRow) {
    //       if (save[a]) {
    //         this.editRow[a] = save[a];
    //       }
    //     }
    //     console.log(this.editRow);
    //     let res = await updateByPtId(this.editRow);
    //     if (res.resultCode == 200) {
    //       this.$emit('save');
    //     }
    //   } else {
    //     this.$notify({
    //       title: '警告',
    //       message: '请输入正确的数据!',
    //       type: 'warning',
    //     });
    //   }
    // },
    //取消操作
    closeDialog() {
      this.$emit('close');
    },
    chooseOrderNo() {
      this.visible = true;
    },
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '索赔单号',
          fieldName: 'cmsClaimNo',
          placeholder: '',
          readonly: true,
          disabled: true,
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '旧件代码',
          fieldName: 'partCode',
          placeholder: '',
          readonly: true,
          disabled: true,
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '旧件名称',
          fieldName: 'partName',
          placeholder: '',
          disabled: true,
          readonly: true,
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '主损件代码',
          fieldName: 'mainPartCode',
          placeholder: '',
          readonly: true,
          disabled: true,
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '主损件名称',
          fieldName: 'mainPartName',
          placeholder: '',
          readonly: true,
          disabled: true,
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '供应商',
          fieldName: 'supName',
          placeholder: '',
          readonly: true,
          disabled: true,
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '索赔单类型',
          fieldName: 'cmsClaimTypeStr',
          placeholder: '',
          readonly: true,
          disabled: true,
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          placeholder: '',
          readonly: true,
          disabled: true,
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '车型',
          fieldName: 'modelName',
          placeholder: '',
          readonly: true,
          disabled: true,
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '交接人',
          fieldName: 'hdBy',
          placeholder: '',
          readonly: true,
          disabled: true,
          initialValue: '',
        },
        {
          type: 'DATE',
          label: '交接时间',
          fieldName: 'hdDate',
          placeholder: '',
          valueFormat: 'yyyy-MM-dd', //返回数据格式
          readonly: true,
          disabled: true,
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '物流名称',
          fieldName: 'expressName',
          placeholder: '',
          readonly: true,
          disabled: true,
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '物流电话',
          fieldName: 'expressTel',
          placeholder: '',
          disabled: true,
          readonly: true,
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '接收人',
          fieldName: 'colBy',
          placeholder: '请输入接收人',
          disabled: true,
          readonly: true,
          initialValue: '',
        },
        {
          type: 'INPUT',
          label: '接收人电话',
          fieldName: 'colTel',
          placeholder: '',
          readonly: true,
          disabled: true,
          initialValue: '',
        },
        {
          type: 'SELECT',
          label: '是否合格',
          fieldName: 'ifQualify',
          placeholder: '请选择是否合格',
          rules: [{ required: true, message: '请选择是否合格', trigger: 'blur' }],
          itemList: [],
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '接收地址',
          fieldName: 'colAddress',
          placeholder: '',
          readonly: true,
          disabled: true,
          initialValue: '',
          selfCols: 2, // 元素占据几行
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'hdRemarks',
          placeholder: '',
          rows: 3,
          selfCols: 4, // 元素占据几行
          disabled: true,
          initialValue: ''
        },
        // {
        //   type: 'UPLOAD_FILE',
        //   label: '上传附件',
        //   fieldName: 'wayFiles',
        //   placeholder: '上传附件...',
        //   initialValue: [],
        //   upload: {
        //     actionUrl: '/api/file/oss/upload',
        //     tipText: '支持PDF、RAR、JPG格式',
        //   },
        //   disabled: true,
        // }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          fixed: 'left',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '附件标题',
          dataIndex: 'title',
          showOverflowTooltip: true,
          render: p => {
            return (
              <a style="color:#bb0a30" href={p.row.fileUrl} target="_blank" download={p.row.title}>
                {p.row.title}
              </a>
            );
          }
        },
      ];
    },
    creatHeader1() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: (props) => {
            return <span>{props.row.index + 1}</span>;
          },
        },
        { title: '操作人', dataIndex: 'createdByStr', sorter: true },
        { title: '审核时间', dataIndex: 'checkAt', sorter: true },
        { title: '审核状态', dataIndex: 'statusStr', sorter: true },
        { title: '审核说明', dataIndex: 'checkRemarks', sorter: true },
      ];
    },
  },
};
</script>

<style lang="less" scoped></style>
